#include<iostream>
#include<string>
using namespace std;
const int N = 5e5 + 10;
int n;
int f[27][27];
string s;
int main()
{
	cin >> n;
	while (n--) {
		cin >> s;
		int len = s.size();
		int l = s[0] - 'a' + 1, r = s[len - 1] - 'a' + 1;
		for (int i = 1; i <= 26; i++) {
			if (f[i][l])f[i][r] = max(f[i][r], f[i][l] + len);
		}
		f[l][r] = max(f[l][r], len);
	}
	int ans = 0;
	for (int i = 1; i <= 26; i++)ans = max(ans, f[i][i]);
	cout << ans << endl;
	return 0;
}